//
//  HWGameLiveRankListCell.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/11/16.
//

import UIKit

class HWGameLiveRankListCell: UITableViewCell {
    
    var numberLabel:UILabel!
    var headImageView:UIImageView!
    var nameLabel:UILabel!
    var priceLabel:UILabel!
    var coinImageView:UIImageView!
    var lineView:UIView!
    
    var model:HWVoiceRoomRankListModel?{
        didSet{
            headImageView.kf.setImage(with: URL(string: model?.face ?? ""))
            nameLabel.text = model?.pet_name
            priceLabel.text = model?.sum_hot
        }
    }

    class func cellWithTableView(tableView:UITableView) -> (HWGameLiveRankListCell) {
        let reUse:String = "HWGameLiveRankListCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameLiveRankListCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameLiveRankListCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        numberLabel = UILabel.init()
        numberLabel.font = UIFont(name: "ZhenyanGB-Regular", size: 20*widthScale)
        numberLabel.textColor = .colorWithHexString(hexString: "#FD5C52")
        contentView.addSubview(numberLabel)
        
        headImageView = UIImageView()
        headImageView.backgroundColor = .red
        headImageView.layer.cornerRadius = 35*widthScale/2
        headImageView.layer.masksToBounds = true
        contentView.addSubview(headImageView)
        
        nameLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 12*widthScale)
        contentView.addSubview(nameLabel)
        
        priceLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 12*widthScale)
        contentView.addSubview(priceLabel)
        
        coinImageView = UIImageView()
        coinImageView.image = UIImage(named: "rankListCoin")
        contentView.addSubview(coinImageView)
        
        lineView = UIView()
        lineView.backgroundColor = .colorWithHexString(hexString: "#CFCFCF")
        contentView.addSubview(lineView)
    }
    
    func initFrame() -> Void {
        numberLabel.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.centerY.equalTo(headImageView)
        }
        
        headImageView.snp.makeConstraints { make in
            make.width.height.equalTo(35*widthScale)
            make.left.equalTo(numberLabel.snp.right).offset(13)
            make.top.equalTo(14)
            make.bottom.equalTo(-5)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.centerY.equalTo(headImageView)
            make.left.equalTo(headImageView.snp.right).offset(3)
        }
        
        coinImageView.snp.makeConstraints { make in
            make.right.equalTo(-24)
            make.centerY.equalTo(headImageView)
            make.height.width.equalTo(13*widthScale)
        }
        
        priceLabel.snp.makeConstraints { make in
            make.centerY.equalTo(headImageView)
            make.right.equalTo(coinImageView.snp.left).offset(-5)
        }
        
        lineView.snp.makeConstraints { make in
            make.height.equalTo(1)
            make.left.equalTo(nameLabel)
            make.right.equalTo(coinImageView)
            make.bottom.equalTo(0)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
